<!DOCTYPE HTML>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description("Test whether WebSocket rejects invalid permessage-deflate parameters.");

window.jsTestIsAsync = true;

var closeEvent;

var testCase = [
    "x-foo",
    "client_max_window_bits=7",
    "client_max_window_bits=16",
    "client_no_context_takeover=foo",
    "client_max_window_bits=8; client_no_context_takeover; x-foo"
];

function doTest(index)
{
    var parameter = testCase[index];
    var url = "ws://localhost:8880/permessage-deflate-invalid-parameter?" + encodeURI(parameter);
    var ws = new WebSocket(url);

    debug("Testing parameter: \"" + parameter + "\"");

    ws.onmessage = function(event)
    {
        var message = event.data;
        testFailed("onmessage() was called. (message = \"" + message + "\")");
    };

    ws.onclose = function(event)
    {
        debug("onclose() was called.");
        closeEvent = event;
        shouldBeFalse("closeEvent.wasClean");
        if (index === testCase.length - 1)
            finishJSTest();
        else
            doTest(index + 1);
    };

    ws.onerror = function(errorEvent)
    {
        testPassed("onerror() was called");
    };
}

doTest(0);

</script>
</body>
</html>
